1
The Hardware Sorting Dilemma
AI032 Lesson 7
00:00

In high-performance hardware, speed is life. Imagine a GPU performing Z-buffering: it must sort millions of depth values per second to decide which pixel is in front. To achieve this, engineers rely on the unsigned number comparator, a streamlined circuit that processes bits from MSB to LSB with zero cognitive overhead.

The Two's Complement Fail

Standard Two's Complement fails this "dumb hardware" test. Because the sign bit is 1 for negative numbers and 0 for positive, a value like -1 (111...) appears bitwise larger than +1 (001...). This creates a discontinuity, forcing hardware to use complex, slower conditional logic to determine magnitude.

The Monotonicity Solution

To restore efficiency, we use Excess Encoding (Biased representation). By shifting the range so that the smallest possible value maps to 000... and the largest to 111..., we ensure that the bit pattern uniquely identifies a numeric value in a way that its lexicographical order corresponds exactly to its numerical order.

Fig 7.1: Two's Comp FailFig 7.2: Excess-3 WinDec | Bits-1 | 111 0 | 000Logic Jump!Dec | Bits-3 | 000-2 | 001-1 | 010 0 | 011Monotonic Increase

This property allows "dumb" hardware comparators to process "smart" floating-point data instantly.

main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>